package com.example.base.baseui;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.eventbus.Subscribe;

public abstract class BaseNormalActivity <VB extends ViewDataBinding> extends AppCompatActivity {
protected VB mBinding;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {

        }catch (Exception e){

        }
        mBinding = DataBindingUtil.setContentView(this, getLayoutId());
        mBinding.setLifecycleOwner(this);
        initView();
        initData();
    }

    protected abstract @LayoutRes int getLayoutId();

    protected abstract void initView();

    protected abstract void initData();

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onEventMainThread(String event) {
        //你的逻辑
    }
    protected void showToast(String msg) {
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }
    protected void showToast(@StringRes int msg) {
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //销毁DataBinding
        if (mBinding != null) {
            mBinding.unbind();
        }
        EventBus.getDefault().unregister(this);
    }
}
